home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1995 February: Tool Chest / Dev.CD Feb 95 / Dev.CD Feb 95.toast / Tool Chest / Development Tools & Languages / • Other Platforms / PCCTS / testcpp / 12 / test.g < prev   
Encoding:
Text File  |  1994-09-14  |  1.0 KB  |  38 lines  |  [TEXT/MPS ]

  1. /* This is test.g which tests a simple DLG-based scanner using string input */
  2.  
  3. <<
  4. typedef ANTLRCommonToken ANTLRToken;
  5.  
  6. #include "DLGLexer.h"
  7.  
  8. main(int argc, char **argv)
  9. {
  10.     if ( argc==1 ) {fprintf(stderr, "how about an argument?\n"); exit(1);}
  11.     DLGStringInput in(argv[1]);    /* create an input stream for DLG */
  12.     DLGLexer scan(&in,2000);/* create scanner reading from stdin with bufsize==2000 */
  13.     ANTLRTokenBuffer pipe(&scan);    /* make a buffered pipe between lexer & parser */
  14.     ANTLRToken aToken;        /* create a token to fill in for DLG */
  15.     scan.setToken(&aToken);
  16.     Expr parser(&pipe);        /* create a parser of type Expr hooked to the scanner */
  17.     parser.init();            /* init the parser; prime lookahead etc... */
  18.  
  19.     parser.e();                /* start parsing at rule 'e' of that parser */
  20. }
  21. >>
  22.  
  23. #token "[\ \t\n]+"    <<skip();>>
  24. #token Eof "@"
  25.  
  26. #tokclass My { IDENTIFIER NUMBER }
  27.  
  28. class Expr {                /* Define a grammar class */
  29.  
  30. e    :    My My Eof
  31.         <<fprintf(stderr, "text is %s,%s\n", $1->getText(), $2->getText());>>
  32.     ;
  33.  
  34. }
  35.  
  36. #token IDENTIFIER    "[a-z]+"
  37. #token NUMBER        "[0-9]+"
  38.